package data;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import dao.BookDao;
import dao.impl.BookDaoImpl;
import pojo.Book;

public class DataLoad {
	
	private final static String FILENAME="D:\\data\\book.m";
	
	public void load(){
		try {
			ObjectInputStream obinInputStream = new ObjectInputStream(new FileInputStream(FILENAME));
			Object obj;
			BookDao bookDao = new BookDaoImpl();
			List<Book> books = new ArrayList<Book>();
			books = (List<Book>) obinInputStream.readObject();
			for (int i = 0; i < books.size(); i++) {
				bookDao.addBook(books.get(i));
				System.out.println(books.get(i).toString());
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		new DataLoad().load();
		long end = System.currentTimeMillis();
		System.out.println(end-start);
	}

}
